<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/admin/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div style="display: none;" id="add" action="">
        <form class="layui-form layui-form-pane" action="">
            <input type="hidden" name="integralMallId" id="integralMallId" />
            <div class="layui-inline">
                <label class="layui-form-label">名称</label>
                <div class="layui-input-inline">
                    <input name="integralMallName" id="integralMallName" value=""  class="layui-input" lay-verify="required" type="text">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">图片</label>
                <div class="layui-input-inline">
                    <input name="integralMallImg" id="integralMallImg" value=""  class="layui-input" lay-verify="required" type="text">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">价格</label>
                <div class="layui-input-inline">
                    <input name="integralPrice" id="integralPrice" value=""  class="layui-input" lay-verify="required" type="text">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">时间</label>
                <div class="layui-input-inline">
                    <input name="createTime" id="createTime" value=""  lay-verify="datetime" class="layui-input" >
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="demo1">立即提交</button>
                </div>
            </div>
        </form>
    </div>


    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">用户职业</label>
                            <div class="layui-input-inline">
                                <input type="text" name="classify" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="employeeTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="conversion">兑换记录</a>
        </script>

    </div>
</div>
<script src="/static/admin/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/admin/system/selectIntegralMall',
            toolbar: '#toolbarDemo',
            cols: [
                [
                    {field: 'integralMallId',  title: 'ID'},
                    {field: 'integralMallName', title: '物品名称'},
                    {field: 'integralPrice', title: '物品价格'},
                    {field: 'createTime', title: '加入时间'},
                    {title: '操作', minWidth: 150, toolbar: '#currentTableBar'}
            ]
            ],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true
        });

        //监听表单提交事件
        form.on('submit(demo1)', function(data){
            var url = "";
            if ($("input[name='integralMallId']").val().trim() == ""){
                url = '/admin/system/insertIntegralMallDetail';
            }else{

            }
            //刷新
            $.ajax({
                url:url,
                type:'post',
                data:data.field,
                dataType:'json',
                success:function (res) {
                    if (res.code == 200){
                        layer.msg(res.message+",即将刷新",function () {
                            //刷新表格
                            table.reload('currentTableId', {
                                url: '/admin/system/selectIntegralMall'
                            });
                        });
                    }else{
                        layer.msg(res.message)
                    }
                }
            })
        });




        /**
         * toolbar监听事件
         */
        table.on('toolbar(employeeTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'add') {  // 监听添加操作
                layer.open({
                    type : 1,
                    content : $('#add')
                });
            }
        });


        //监听操作
        table.on('tool(employeeTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'conversion') {
                layer.open({
                    title: '兑换详情',
                    type:1,
                    shadeClose : true,
                    area : [ '700px', '460px' ],//大小
                    content: $("#dibId"),
                    end : function() {
                        $('[lay-id="#currentTableId2"]').css("display","none");
                    }
                });
                table.render({
                    elem: '#currentTableId2'
                    ,url:'/admin/system/selectIntegralMallDetail?integralMallId='+data.integralMallId
                    ,totalRow: true
                    ,cols: [
                        [
                        {field:'integralMallDetailId',title: 'Id'},
                        {field:'name', title:'客户名称'},
                        {field:'createTime', title:'兑换时间'}
                    ]
                    ],
                    limits: [10, 15, 20, 25, 50, 100],
                    limit: 15,
                    page: true
                });
            } else if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                    $.ajax({
                        url:"/admin/system/deleteIntegralMall",
                        type:"get",
                        data:{
                            integralMallId:data.integralMallId
                        },
                        dataType:"text",
                        success:function(data){
                            table.reload('currentTableId', {
                                url:"/admin/system/selectIntegralMall",
                                type:"post"
                            });
                        }
                    })
                    obj.del();
                    layer.close(index);
                });
            }
        });

    });

    //时间选择器
    layui.use(['layer', 'form', 'table', 'laydate'], function () {
        var layer = layui.layer,
            $ = layui.jquery,
            form = layui.form,
            laydate = layui.laydate,
            table = layui.table;


        var endDate = laydate.render({//渲染结束时间选择
            elem: '#createTime',//通过id绑定html中插入的end
            type: 'datetime',
            min: "1970-1-1 00:00:00",//设置min默认最小值
            done: function (value, dates) {
                beginDate.config.max = {
                    year: dates.year,
                    month: dates.month - 1,//关键
                    date: dates.date,
                    hours: dates.hours,
                    minutes: dates.minutes,
                    seconds: dates.seconds
                }
            }
        });
    });

</script>
<div  id="dibId">
    <table class="layui-hide" id="currentTableId2"  lay-filter="currentTableId2" style="display:none;"></table>
</div>
</body>
</html>
